package net.stogi.common.gwt.frame.client.module.impl;

import java.util.HashMap;
import java.util.Map;

import net.stogi.common.gwt.frame.client.module.Module;
import net.stogi.common.gwt.frame.client.module.ModuleFactory;
import net.stogi.common.gwt.frame.client.module.ModuleFactoryRegistry;

public class BasicModuleFactoryRegistry implements ModuleFactoryRegistry {

	private final Map<Class<?>, ModuleFactory<?>> factories;

	public BasicModuleFactoryRegistry() {
		factories = new HashMap<Class<?>, ModuleFactory<?>>();
	}

	@Override
	public void clearHandlers() {
		factories.clear();
	}

	@Override
	@SuppressWarnings("unchecked")
	public <M extends Module> ModuleFactory<M> findFactory(Class<M> clazz) {
		return (ModuleFactory<M>) factories.get(clazz);
	}

	@Override
	public <M extends Module> void registerFactory(Class<M> clazz, ModuleFactory<M> factory) {
		factories.put(clazz, factory);
	}

	@Override
	public <M extends Module> void unregisterFactory(Class<M> clazz) {
		factories.remove(clazz);
	}
}
